package com.remoter.configure.properties;

import java.io.InputStream;
import java.util.Map.Entry;
import java.util.Properties;

import com.remoter.basic.configure.support.AbstractConfiguration;
import com.remoter.basic.util.ServiceLoader.MetaName;

/**
 * @author			koko
 * @date 			2017-08-08 14:42:10
 * @description 	properties格式的属性文件扩展点实现
 */
@MetaName("properties")
public class PropertiesConfiguration extends AbstractConfiguration{
	
	private static final Properties properties = new Properties();
	
	@Override
	protected String getValue(String name) {
		return properties.getProperty(name);
	}
	
	public PropertiesConfiguration() {
		String path = this.getConfigFile();
		try(InputStream inputStream = this.getClass().getResourceAsStream(path)){
			if(null == inputStream){
				logger.warn("config file not found :" + path);
			}else{
				properties.load(inputStream);
			}
		}catch(Exception e){
			logger.error(e.getMessage(),e);
		}
		if(logger.isDebugEnabled()){
			for(Entry<Object,Object> entry : properties.entrySet()){
				logger.debug(String.format("load config [%s=%s]",entry.getKey(),entry.getValue()));
			}
		}
	}
	
}